import random

from ua_info import  ua_list
from urllib import request
from urllib import parse
# url ='https://tieba.baidu.com/f/index/forumpark?cn=&ci=0&pcn=%E4%BD%93%E8%82%B2%E8%BF%B7&pci=275&ct=&st=new&pn={}'
#
#
# for page in range(30):
#     print(page+1)
#     urlf =  url.format(page+1)
#     print(urlf)

url ='https://tieba.baidu.com/f/index/forumpark?cn=&ci=0&pcn=%E4%BD%93%E8%82%B2%E8%BF%B7&pci=275&ct=&st=new&pn=1'

headers={
    'User-Agent': random.choice(ua_list),
}

req = request.Request(headers=headers,url=url)
res = request.urlopen(req)
response = res.read().decode('utf-8','ignore')
with open("bdtb.html", 'w', encoding='utf-8') as f:
    f.write(response)

print(response)

